<template>
  <div class="movie">
    <section>
      <div class="swiper-header"></div>
      <div :class="['page-wrap' ,'n-hot', 'show',{'stop':loading}]">
        <div class="page">
          <!-- 最受好评电影 -->
          <div id="top-rated-wrap" v-if="Mostpraised">
            <div class="top-rated">
              <p class="title">{{ Mostpraised.title }}</p>
              <div class="top-rated-list">
                <router-link
                  :to="'/detail?id=' + item.movieId"
                  class="top-rated-item"
                  v-for="item in Mostpraised.movieList"
                  :key="item.movieId"
                >
                  <div class="poster">
                    <img :src="item.poster" alt="" />
                    <span class="wish-bg"></span>
                    <span class="score" v-if="item.score">
                      观众评分 &nbsp;
                      <span class="rated-score">{{item.score}}</span>
                    </span>
                    <span class="score" v-if="!item.score">
                      暂无评分
                    </span>
                  </div>
                  <h5 class="name line-ellipsis">{{ item.name }}</h5>
                </router-link>
              </div>
            </div>
          </div>
          <!-- 热映电影列表 -->
          <div class="list-wrap" v-if="movieList">
            <van-list
              v-model="loading"
              :finished="finished"            
              @load="onLoad"
            >
              <div class="item" v-for="(item, index) in movieList" :key="index">
                <a class="main-block clearfix">
                  <div class="avatar" @click="detail(item.id)">
                    <div class="default-img-bg">
                      <img :src="item.img" alt="" />
                    </div>
                  </div>
                  <div class="mb-outline-b content-wrapper">
                    <div class="content">
                      <div class="movie-title box-flex">
                        <div class="title line-ellipsis">{{ item.nm }}</div>
                        <span
                          class="version v2d imax"
                          v-if="item.version"
                        ></span>
                      </div>
                      <div class="detail">
                        <div class="score line-ellipsis" v-if="item.sc != 0">
                          <span class="score-suffix">观众评 </span>
                          <span class="grade">{{ item.sc }}</span>
                        </div>
                        <div class="score line-ellipsis" v-if="item.sc == 0">
                          <span class="score-suffix">暂无评分 </span>
                          <span class="grade"></span>
                        </div>
                        <div class="actor line-ellipsis">
                          主演:{{ item.star }}
                        </div>
                        <div class="show-info line-ellipsis">
                          {{ item.showInfo }}
                        </div>
                      </div>
                    </div>
                    <div class="button-block" @click="moviebuy(item.id)">
                      <div class="btn">
                        <span class="fix">购票</span>
                      </div>
                    </div>
                  </div>
                </a>
              </div>
              <!-- <van-loading size="24px" v-if="loading">加载中...</van-loading> -->
            </van-list>
          </div>
            <div class="lodaing" v-if="showview">
              <div class="img">
                <img class="img1" src="../assets/images/maoyan01.png" alt="" />
                <img class="img2" src="../assets/images/maoyan02.png" alt="" />
              </div>
            </div>
          <!-- <div class="hot-celebrities">
            <p class="title">热门影人</p>
            <div class="hot-celebrities-list">
              <div class="celebrity-item">
                <a href="#">
                  <img
                    class="celebrity-img"
                    src="../assets/images/贾冰.jpg"
                    alt=""
                  />
                  <h5 class="name line-ellipsis">贾冰</h5>
                </a>
              </div>
              <div class="celebrity-item">
                <a href="#">
                  <img
                    class="celebrity-img"
                    src="../assets/images/王俊凯.jpg"
                    alt=""
                  />
                  <h5 class="name line-ellipsis">王俊凯</h5>
                </a>
              </div>
              <div class="celebrity-item">
                <a href="#">
                  <img
                    class="celebrity-img"
                    src="../assets/images/韩雪.jpg"
                    alt=""
                  />
                  <h5 class="name line-ellipsis">韩雪</h5>
                </a>
              </div>
              <div class="celebrity-item">
                <a href="#">
                  <img
                    class="celebrity-img"
                    src="../assets/images/李梦.jpg"
                    alt=""
                  />
                  <h5 class="name line-ellipsis">李梦</h5>
                </a>
              </div>
              <div class="celebrity-item">
                <a href="#">
                  <img
                    class="celebrity-img"
                    src="../assets/images/林永健.jpg"
                    alt=""
                  />
                  <h5 class="name line-ellipsis">林永健</h5>
                </a>
              </div>
            </div>
          </div>
          <div class="hot-news">
            <p class="title">娱乐热点</p>
            <div class="hot-news-list">
              <div class="news-item">
                <a href="#">
                  <p>
                    1.&nbsp;《钢铁意志》首日票房超过2000万，勇夺本周票房榜前四名
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    2.&nbsp;电影《新灰姑娘2》正在热映！口碑获赞小公主和小王子都喜欢
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    3.&nbsp;电影《平凡英雄》小演员与李冰冰冯绍峰黄晓明两帝一后同台飙戏
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>4.&nbsp;上映第三天票房逆跌！《万里归途》票房破6亿</p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    5.&nbsp;《哥，你好》“我爸我妈恋爱甜”正片片段，重阳看喜剧思念暖心怀
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    6.&nbsp;《搜救》“拥抱”版海报 爸爸虽非英雄 但拼死也要护你周全
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    7.&nbsp;少年强则中国强！“新大头儿子”电影5致敬中国航天事业
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>8.&nbsp;电影《新灰姑娘2》上映！一起走进童话魔法世界</p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>
                    9.&nbsp;《搜救》“孤注一掷”版终极预告 父母是孩子最后一道防线
                  </p>
                </a>
              </div>
              <div class="news-item">
                <a href="#">
                  <p>10.&nbsp;《万里归途》票房破4亿！曝“成为外交官”特辑</p>
                </a>
              </div>
            </div>
          </div> -->
        </div>
      </div>
    </section>
  </div>
</template>

<script>
import { getMostpraised, getHotmovies, getMoreHotmovies } from "../api/home.js";

export default {
  data() {
    return {
      Mostpraised: null, //最受好评电影
      movieIds: null,//电影id
      cityId:null,//城市id
      movieList: [],//电影列表
      list: [],//电影id
      finished: false,
      startIds: 0,//首次加载列表数
      loading:false,//加载动画
      loadingTime:null,
      showview:true,

    };
  },
  methods: {
    //获取最受好评电影数据
    getWellFilm() {
      getMostpraised().then((data) => {
        if (data) {
          setTimeout(()=>{
            this.showview=false
          },500)
        }
        this.Mostpraised = data;
      });
    },
    //热映电影数据&&更多电影
    onLoad() {
      getHotmovies().then((data) => {
        this.movieIds = data.movieIds;
        this.list = [...this.movieIds];
        getMoreHotmovies({
          movieIds: this.list
            .slice(this.startIds, this.startIds + 10)
            .toString(),
        })
          .then((data) => {
            // console.log(data);
            this.movieList = [...this.movieList, ...data.coming];
            // console.log("增加了",this.movieList.length);
              this.loadingTime=setTimeout(() => {
                  this.loading=false
              }, 500);  
      
              this.startIds += 10;
              if (this.startIds >= 50) {
                this.finished = true;
              }
          })
      });
    },
    detail(id){
      this.$router.push({path:'/detail',query:{id}})
    },
    moviebuy(id){
      this.$router.push({path:'/ticket',query:{movieId:id,cityId:this.cityId}})
    }
  },
  created() {
    this.getWellFilm();
    this.cityId=this.$route.query.id==undefined?20:this.$route.query.id
  },
  beforeDestroy() {
    clearTimeout(this.loadingTime)
  },
};
</script>

<style lang="less" scoped>
.movie {
  overflow: hidden;
  flex: 1;
  position: relative;

  .page-wrap {
    display: block;
    height: 100%;
    width: 100%;
    overflow-y: scroll;
    position: absolute;

    .page {
      display: block;
      flex: auto;

      .top-rated {
        padding: 12px 15px;
        background-color: #fff;
        margin-bottom: 10px;

        .title {
          font-size: 14px;
          color: #333;
          margin: 0 0 12px;
        }

        .top-rated-list {
          overflow-x: scroll;
          white-space: nowrap;
          font-size: 0;

          .top-rated-item {
            display: inline-block;
            width: 85px;
            overflow: hidden;
            margin-right: 10px;

            .poster {
              width: 85px;
              height: 115px;
              position: relative;
              margin-bottom: 6px;
              background-color: #e1e1e1;
              background-size: 100% 100%;

              .wish-bg {
                display: inline-block;
                width: 100%;
                height: 35px;
                position: absolute;
                bottom: 0;
                background-image: linear-gradient(
                  -180deg,
                  rgba(77, 77, 77, 0),
                  #000
                );
              }

              .score {
                position: absolute;
                left: 4px;
                bottom: 4px;
                color: #faaf00;
                font-size: 11px;
                font-weight: 600;

                .rated-score {
                  color: #faaf00;
                  font-size: 11px;
                  font-weight: 600;
                }
              }
            }

            .name {
              height: 19.5px;
              line-height: 19.5px;
              font-size: 13px;
              color: #222;
              margin: 0 0 3px;
              font-weight: bold;
            }
          }

          &::-webkit-scrollbar {
            display: none;
          }
        }
      }

      .list-wrap {
        // height: 100%;
        background-color: #f5f5f5;
        // overflow-y: scroll;

        .item {
          display: block;
          padding-left: 15px;
          background-color: #fff;

          .main-block {
            width: 100%;
            position: relative;

            .avatar {
              width: 64px;
              height: 95px;
              margin-top: 12px;
              position: relative;
              float: left;

              &::before {
                content: "";
                display: block;
                position: absolute;
                width: 46px;
                height: 46px;
                background-repeat: no-repeat;
                background-size: contain;
              }
              .default-img-bg{
                width: 64px;
                height: 90px;

                &>img{
                  width: 100%;
                  height: 100%;
                }
              }
            }

            .content-wrapper {
              height: 90px;
              max-height: 90px;
              margin-left: 74px;
              position: relative;
              padding: 12px 14px 12px 0;

              .content {
                padding-right: 5px;
                margin-right: 48px;

                .movie-title {
                  height: 24px;
                  margin-bottom: 7px;
                  max-height: 24px;
                  line-height: 24px;

                  .title {
                    font-size: 17px;
                    font-weight: 700;
                    color: #333;
                    padding-right: 5px;
                    flex-shrink: 1;
                  }

                  .v2d {
                    width: 43px;
                    height: 14px;
                    background-image: url(../assets/images/v2dimax.png);
                  }
                }

                .detail {
                  box-sizing: border-box;
                  line-height: 1;
                  overflow: hidden;

                  .score {
                    .grade {
                      font-size: 15px;
                      font-weight: 700;
                      color: #faaf00;
                    }
                  }

                  .show-info,
                  .actor {
                    margin-top: 6px;
                    line-height: 15px;
                  }
                }
              }

              .button-block {
                font-size: 13px;
                position: absolute;
                right: 15px;
                top: 0;
                bottom: 0;
                height: 27px;
                margin: auto;

                .btn {
                  width: 54px;
                  height: 28px;
                  background-color: #f03d37;
                  box-shadow: 0 0.04rem 0.04rem 0 rgb(240 61 55 / 15%);
                  display: flex;
                  justify-content: center;
                  align-items: center;
                  box-sizing: border-box;
                  cursor: pointer;
                  border-radius: 14px;

                  .fix {
                    color: #fff;
                    white-space: nowrap;
                    font-size: 13px;
                    font-weight: 500;
                  }
                }
              }
            }
          }
        }
      }
    }
    .stop{
        overflow: hidden;
    }

    &::-webkit-scrollbar {
      display: none;
    }
  }
  .stop{
    overflow: hidden;
  }

  .n-hot {
    background-color: #f5f5f5;
  }

  .show {
    display: block;
    height: 100%;
  }
}

.hot-celebrities {
  background-color: #fff;
  margin: 10px 0;
  padding: 12px 15px;

  .title {
    font-size: 14px;
    color: #333;
    margin-bottom: 12px;
  }

  .hot-celebrities-list {
    overflow: scroll;
    white-space: nowrap;
    font-size: 0;

    .celebrity-item {
      display: inline-block;
      overflow: hidden;
      width: 85px;
      margin-right: 10px;

      .celebrity-img {
        width: 85px;
        height: 115px;
        display: block;
        margin-bottom: 6px;
      }

      .name {
        font-size: 13px;
        margin-bottom: 3px;
        color: #222;
        font-weight: bold;
      }
    }

    &::-webkit-scrollbar {
      display: none;
    }
  }
}

.hot-news {
  padding: 12px 15px;
  background-color: #fff;

  .title {
    font-size: 14px;
    color: #333;
    margin-bottom: 12px;
  }

  .hot-news-list {
    .news-item {
      & > a {
        & > p {
          height: 21px;
          line-height: 21px;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          width: 95%;
          font-size: 14px;
          margin: 14px 0;
          color: #333;
        }
      }
    }
  }
}
@keyframes animation1 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
.lodaing {
  width: 100%;
  height: 85vh;
  position: fixed;
  bottom: 50px;
  left: 0;
  background-color: #fff;
  z-index: 99;

  .img {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    margin: auto;
    width: 45px;
    height: 45px;

    img {
      position: relative;
      width: 100%;
      height: 100%;
      z-index: 3;
    }

    .img2 {
      position: absolute;
      top: 0;
      right: 0;
      left: 0;
      bottom: 0;
      margin: auto;
      animation: animation1 1s linear 0s infinite;
    }
  }
}
::v-deep .van-loading{
  height: 45px;
  line-height: 45px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 45px;
  background-color: #f5f5f5;
}
</style>